using UnityEngine;

public class CheckPoint : MonoBehaviour
{
    private Animator anim;

    public string checkPointID;
    public bool activationStatus;
    public GameObject keyTips_E;
    private bool isPlayerInCheckPoint;


    private void Start()
    {
        anim = GetComponent<Animator>();
    }

    private void Update()
    {
        if(isPlayerInCheckPoint && Input.GetKeyDown(KeyCode.E))
            ActiveCheckPoint();
    }

    [ContextMenu("Generate CheckPoint ID")]
    private void GenerateID()
    {
        checkPointID = System.Guid.NewGuid().ToString();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.GetComponent<Player>() != null)
        {
            SetKeyTips_E(true);
            isPlayerInCheckPoint = true;
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.GetComponent<Player>() != null)
        {
            SetKeyTips_E(false);
            isPlayerInCheckPoint = false;
        }
    }

    public void ActiveCheckPoint()
    {
        activationStatus = true;
        anim.SetBool("Active", true);
    }

    public void SetKeyTips_E(bool _isActivated)
    {
        keyTips_E.SetActive(_isActivated);
    }
}
